﻿using System;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Input;



namespace Crm2011.Framework.Connect.Commands
{
    internal class NewProfileCommand : ICommand
    {
        private readonly ConnectionListView _view;



        public NewProfileCommand(ConnectionListView view)
        {
            _view = view;
        }



        public void Execute(object view)
        {
            ConnectionProfile profile = new ConnectionProfile
                {
                    ConnectionId = Guid.NewGuid(),
                    ConnectionName = "<new connection>"
                };


            CrmConnectionEditor cnsEdit = new CrmConnectionEditor();
            cnsEdit.SetConnectionProfile ( profile);
            var result =  cnsEdit.ShowDialog();
            if (result == DialogResult.OK)
            {
                _view.CurrentProfile = cnsEdit.GetConnectionProfile();
            }
        }



        public bool CanExecute(object parameter)
        {
            return true;
        }



        public event EventHandler CanExecuteChanged;
    }
}